﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="AnagraficaMagazzini.aspx.cs" Inherits="FimetContoDeposito.Anagrafiche.AnagraficaMagazzini" %>

<%@ Register assembly="GrayParrot.Web.Controls" namespace="GrayParrot.Web.Controls" tagprefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <asp:PlaceHolder ID="PlaceHolder1" runat="server">        
        <%: Styles.Render("~/bundles/Datatables/css") %>
        <%: Scripts.Render("~/bundles/Datatables") %>
    </asp:PlaceHolder>

    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.Core.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.DataTables.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.Modals.js"></script> 
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <!-- 
        Sitemap Menu item:
        <siteMapNode url="~/AnagraficaFamiglie.aspx" title="AnagraficaFamiglie" description="AnagraficaFamiglie" image="fa-laptop" id="AnagraficaFamiglie"/>
    -->
    <section class="panel">
	    <header class="panel-heading">
			<b>Anagrafica Magazzini</b>
		</header>
		<div class="panel-body">

            <!-- PUT YOUR CONTENT HERE -->
                <iframe id='iframeCrud' frameborder="0" style="width:700px; height:600px; display:none"></iframe>
                <div id="crudDialog" title="" style="display:none"></div>

                <cc1:JQDataTable ID="JQDTable" runat="server" 
                     SelectionMode="Single" 
                     RenderScripts="false" 
                     BootstrapClasses="table table-hover table-bordered table-condensed">
                    <FeaturesConfig>
                        <Features>
<%--                            <cc1:Searching Value="Both">
                                <Filters>
                                    <cc1:TextColumnFilter ColumnName="nome" />
                                    <cc1:TextColumnFilter ColumnName="DataCreazione" />
                                    <cc1:SelectColumnFilter ColumnName="Abilitato" SelectType="Select2" />
                                    <cc1:TextColumnFilter ColumnName="Note" />
                                    <cc1:ColumnFilter ColumnName="Nome" Type="Text" />
                                    <cc1:ColumnFilter ColumnName="DataCreazione" Type="Text" />
                                    <cc1:ColumnFilter ColumnName="Abilitato" Type="Select" />
                                    <cc1:ColumnFilter ColumnName="Note" Type="Text" />
                                </Filters>
                            </cc1:Searching>--%>
                            <cc1:AutoWitdh Value="true" />
                            <cc1:ScrollY Value="500" ScrollCollapse="true" />
                            <%--<cc1:LengthChange Value="false" />--%>
                            <cc1:Paging PagingType="FullNumbers" PageLength="20" />
                        </Features>
                    </FeaturesConfig>
                    <ControllerConfig Url="/api/AnagraficaMagazzini/Load" LoadingMode="OnLoad">
                    </ControllerConfig>
                    <ColumnsConfig Key="Id">
                        <Columns>
                            <cc1:TextColumn Name="Id" Header="Id" Visible="false" />
                            <cc1:TextColumn Name="Nome" Header="Nome" />
                            <cc1:TextColumn Name="DataCreazione" Header="Data Creazione" />
                            <cc1:TextColumn Name="Abilitato" Header="Abilitato" />
                            <cc1:TextColumn Name="Note" Header="Note" />
                            <cc1:TextColumn Name="FCD_Customer.RagioneSociale" Header="Cliente" />
                        </Columns>
                    </ColumnsConfig>
                    <Buttons>
                        <cc1:CrudAddButton Text="Aggiungi" Callback="LoadAddDialog" />
                        <cc1:CrudEditButton Text="Modifica" Callback="LoadEditDialog" />
                        <cc1:CrudDeleteButton Text="Cancella" Callback="DeleteDialog" />
                    </Buttons>
                </cc1:JQDataTable>

		</div>
	</section>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="LocaJavascript" runat="server">
    <% HttpContext.Current.Response.Write(this.JQDTable.RenderScriptsManually()); %>

<script>
    function CloseDialog(response) {
        $('#crudDialog').dialog('close');

        ShowResponseMessage(response);
    }

    function LoadAddDialog() {

        $("#iframeCrud").prop('src', 'AnagraficaMagazzini_CRUD.aspx').appendTo("#crudDialog");
        $("#iframeCrud").show();

        m_dialog = $("#crudDialog").dialog({
            title: 'Nuovo Magazzino',
            width: 'auto',
            height: 'auto',
            modal: true,
            close: function () {
                RedrawGrid(m_tableJQDTable);

                $("#iframeCrud").contents().remove();
                $('#iframeCrud').hide();
            }
        });
    }

    function LoadEditDialog() {

        var p = null;

        p = GetSelectedData(m_tableJQDTable).Id;

        var url = 'AnagraficaMagazzini_CRUD.aspx?id=' + p;

        $("#iframeCrud").prop('src', url).appendTo("#crudDialog");
        $("#iframeCrud").show();

        m_dialog = $("#crudDialog").dialog({
            title: 'Modifica Magazzino',
            width: 'auto',
            height: 'auto',
            modal: true,
            close: function () {
                RedrawGrid(m_tableJQDTable);

                $("#iframeCrud").contents().remove();
                $('#iframeCrud').hide();
            }
        });
    }

    function DeleteDialog() {
        var p = null;

        var row = GetSelectedData(m_tableJQDTable);

        p = row.Id;

        var url = '/api/AnagraficaMagazzini/Delete';

        $("#crudDialog").html("Confermi la cancellazione dell'elemento con codice: " + p + " ?");

        // Define the Dialog and its properties.
        $("#crudDialog").dialog({
            resizable: false,
            modal: true,
            title: "Cancella elemento",
            height: 250,
            width: 400,
            buttons:[
                {
                    id: "Yes",
                    text: "Si",
                    click: function () {
                        $(this).dialog("option", { buttons: {} });
                        //$(this).empty();
                        $(this).dialog('close');

                        $.ajax({
                            type: "POST",
                            url: url,
                            data: JSON.stringify({ id: p }),
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (response) {
                                RedrawGrid(m_tableJQDTable);

                                $("#crudDialog").empty();

                                alert(response);
                            },
                            failure: function (response) {

                                $("#crudDialog").empty();

                                alert(response);
                            }
                        });
                    }
                },
                {
                    id: "No",
                    text: "No",
                    click: function () {
                        $("#crudDialog").empty();

                        $(this).dialog('close');
                    }
                }
            ]
        });
    }
</script>
</asp:Content>